<template>
  <div style="padding: 10px">
    <el-input v-model="numKey" clearable placeholder="根据课程代码检索" style="width: 20%;margin-top: 5px"/>
    <el-button style="margin: 5px" type="primary" @click="searchByNum">查询</el-button>
    <el-input v-model="nameKey" clearable placeholder="根据课程名称检索" style="width: 20%;margin-top: 5px"/>
    <el-button style="margin: 5px" type="primary" @click="searchByName">查询</el-button>
    <el-input v-model="teacherKey" clearable placeholder="根据授课教师检索" style="width: 20%;margin-top: 5px"/>
    <el-button style="margin: 5px" type="primary" @click="searchByTeacher">查询</el-button>
    <el-table :data="tableData" border style="width: 100%" stripe>
      <el-table-column fixed prop="courseName" label="课程名" sortable/>
      <el-table-column fixed prop="courseNumber" label="课程编号"/>
      <el-table-column prop="schoolId" label="开课院系"/>
      <el-table-column prop="coursePeriod" label="学时"/>
      <el-table-column prop="courseCredit" label="学分"/>
      <el-table-column prop="workNumber" label="任课教师"/>
      <el-table-column prop="courseDesc" label="课程介绍"/>
<!--      <el-table-column prop="time" label="上课时间"/>-->
<!--      <el-table-column prop="place" label="上课地点"/>-->
      <el-table-column prop="courseCapacity" label="选课容量"/>
      <el-table-column prop="options" label="操作" width="120px">
        <template #default="scope">
          <el-button type="text" @click="handle1Select(scope.row.courseNumber)">一轮选课</el-button>
          <el-button type="text" @click="handle2Select(scope.row.courseNumber)">二轮选课</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "CourseOption",
  components:{
  },
  data(){
    return{
      tableData:[],
      numKey: '',
      nameKey: '',
      teacherKey: '',
      round:'',
    }
  },
  created() {
    this.load()
  },
  methods:{
    load(){
      // request.get("http://localhost:8082/").then(res=>{
      //   this.tableData=res.data
      // })
    },
    searchByNum() {
      request.get("http://124.70.179.188:8082/selCourse/stu/findByCourseNum?stunum="+localStorage.getItem('userid')+"&cnum=" + this.numKey).then(res => {
        this.tableData = res.data
        console.log(res.data)
            this.load();
      }
      )
    },
    searchByName() {
      request.get("http://124.70.179.188:8082/selCourse/stu/findByCourseName?stunum="+localStorage.getItem('userid')+"&cname=" + this.nameKey).then(res => {
            this.tableData = res.data
            this.load();
          }
      )
    },
    searchByTeacher() {
      request.get("http://124.70.179.188:8082/selCourse/stu/findByTeaName?stunum="+localStorage.getItem('userid')+"&teaname=" + this.teacherKey).then(res => {
            this.tableData = res.data
            this.load();
          }
      )

    },
    handle1Select(number){
      request.get("http://124.70.179.188:8082/selCourse/round1Sel?stunum="+localStorage.getItem('userid')+"&courseid=" + number).then(res => {
            if (res.code === 0) {
              this.$message({
                type: "success",
                message:res.message
              })
            } else {
              this.$message({
                type: "error",
                message: res.msg
              })
            }
            this.load();
          }
      )
    },
    handle2Select(number){
      request.post("http://124.70.179.188:8082/selCourse/round2Sel?stunum="+localStorage.getItem('userid')+"&courseid=" + number).then(res => {
            if (res.code === 0) {
              this.$message({
                type: "success",
                message:res.message
              })
            } else {
              this.$message({
                type: "error",
                message: res.msg
              })
            }
            this.load();
          }
      )
    }
  }
}
</script>

<style scoped>

</style>